package com.stylefeng.guns.biz.api.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.redis.RedisService;
import com.stylefeng.guns.core.result.JsonReturnHelper;

import org.springframework.web.bind.annotation.RequestParam;

import com.stylefeng.guns.modular.platform.model.SmallInfo;
import com.stylefeng.guns.modular.platform.service.ISmallInfoService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-07-24 17:04:18
 */
@RestController
@RequestMapping("/api/pc/small")
public class SmallController extends BaseController {

	@Autowired
	private ISmallInfoService smallInfoService;
    @Autowired
    private RedisService redisService;

	/**
	 * 新增
	 */
	@RequestMapping(value = "/addInfo")
	@ResponseBody
	public Object add(SmallInfo smallInfo) {
		String code = redisService.getStr(smallInfo.getMobile());
		Map<String, String> retMap = new HashMap<>();
		if (StringUtils.isEmpty(code) || !code.equals(smallInfo.getCode())) {
			retMap.put("retCode", "000001");
			retMap.put("retMsg", "验证码错误!");
			return JsonReturnHelper.getSuccessWithData(retMap);
		}

		smallInfo.setUpdateTime(new Date());
		smallInfo.setScrapyTime(new Date());
		smallInfo.setStatus(0);
		boolean falg = smallInfoService.insert(smallInfo);
		if (falg) {
			retMap.put("retCode", "000000");
			retMap.put("retMsg", "保存成功!");
		}
		return JsonReturnHelper.getSuccessWithData(retMap);
	}

	/**
	 * 获取列表
	 */
	@RequestMapping(value = "/getList", method = RequestMethod.GET)
	@ResponseBody
	public Object getList(Page page, SmallInfo smallInfo) {
		return smallInfoService.getList(page, smallInfo);
	}

	/**
	 * 获取列表
	 */
	@RequestMapping(value = "/getRandomList", method = RequestMethod.GET)
	@ResponseBody
	public Object getRandomList() {
		return smallInfoService.getRandomList();
	}

	/**
	 * 获取热门列表
	 */
	@RequestMapping(value = "/getHotList", method = RequestMethod.GET)
	@ResponseBody
	public Object getHotList() {
		return smallInfoService.getHotList();
	}

	/**
	 * 获取最新列表
	 */
	@RequestMapping(value = "/getNewList", method = RequestMethod.GET)
	@ResponseBody
	public Object getNewList() {
		return smallInfoService.getNewList();
	}

	/**
	 * 获取最新列表
	 */
	@RequestMapping(value = "/getTypeList", method = RequestMethod.GET)
	@ResponseBody
	public Object getTypeList() {
		return smallInfoService.getTypeList();
	}

}
